<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Index</title>
    <script type="text/javascript">
        var ws = null;
        function startWebSocket() {
            ws = new WebSocket("ws://localhost:8080/websocket");
//            if ('WebSocket' in window)
//            {
//                console.log("support Websocket")
//                ws = new WebSocket("ws://localhost:8080/websocket/1");
//            }
//            else if ('MozWebSocket' in window)
//            {
//                console.log("support MozWebsocket")
//                ws = new MozWebSocket("ws://websocket/2");
//            }
//            else
//                alert("not support");
            // 打开连接
            ws.onopen = function(evt) {
                alert("open");
            };
            // 收到消息
            ws.onmessage = function(evt) {
                alert(evt.data);
            };

            // 断开连接
            ws.onclose = function(evt) {
                alert("close");
            };


        }

        // 向服务端发送消息
        function sendMsg() {
            ws.send(document.getElementById('writeMsg').value);
        }
    </script>
</head>
<body onload="startWebSocket();">
<input type="text" id="writeMsg"/>
<input type="button" value="send" onclick="sendMsg()"/>
</body>
</html>